// lib/app/presentation/screens/user_list_screen.dart
import 'package:flutter/material.dart';
import 'package:flutter_clean_architecture/app/domain/models/user.dart';
import 'package:flutter_clean_architecture/providers.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class UserListScreen extends ConsumerWidget {
  const UserListScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // 使用 ref.watch 来监听 getUserUseCaseProvider 的变化
    final getUserUseCase = ref.watch(getUserUseCaseProvider);

    return Scaffold(
      appBar: AppBar(title: const Text('Users')),
      body: FutureBuilder(
        future: getUserUseCase.execute(),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Center(child: CircularProgressIndicator());
          } else if (snapshot.hasError) {
            return Center(child: Text('Error: ${snapshot.error}'));
          } else {
            final users = snapshot.data as List<User>;
            return ListView.builder(
              itemCount: users.length,
              itemBuilder: (context, index) {
                final user = users[index];
                return ListTile(title: Text(user.name));
              },
            );
          }
        },
      ),
    );
  }
}
